package com;

import com.yhq.DBconn;

import  java.sql.*;
public class Main {

    public static void main(String[] args) {
//	    1.注册驱动
        Connection conn = null;
        Statement statement = null;
        ResultSet res = null;
        try {

//            2.获取数据库连接
            String url = "jdbc:mysql://localhost:3306/test";
//            String url = "url=jdbc:mysql://localhost:3306/bjnode/framework?characterEncoding=utf8&useSSL=false";
            String user = "root";
            String password = "123456";

            try {
                Class.forName("com.mysql.jdbc.Driver");
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }

            conn = DriverManager.getConnection(url,user,password);
//            3.获取数据操作的对象
            statement = conn.createStatement();
//            4.执行SQL语句，DML语句
//            5.处理查询结果集
            while (res.next()) {
                String enmae = res.getString("name");

                System.out.println(enmae);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            if (res != null) {
                try {
                    res.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}
